//
//  FoodDetailViewController.m
//  ZooNgonDoiOS
//
//  Created by Tran Minh Long on 11/8/12.
//  Copyright (c) 2012 Personal. All rights reserved.
//

#import "FoodDetailViewController.h"
#import "FoodDetailTableView.h"
#import "DetailViewController.h"
#import "ZooFoodBean.h"
#import "CommentViewController.h"

@implementation FoodDetailViewController
@synthesize foodDetailDelegate;
@synthesize _foodBean;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (id) initWithFood: (ZooFoodBean*) zooFoodBean {
    
    self = [self initWithNibName:nil bundle:nil];
    
    if (self) {
        _screenSize = self.view.bounds.size;
        
        _foodBean = zooFoodBean;
        
        [self initHeaderView];
        [self initContent];
    }
    
    return self;
}

- (void) initHeaderView {
    _vHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _screenSize.width, 48)];
    _vHeader.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:IMG_NAV_BACKGROUND]];
    
    _btnBack = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 48, 48)];
    [_btnBack setBackgroundImage:[UIImage imageNamed:IMG_BACK_NORMAL] forState:UIControlStateNormal];
    [_btnBack setBackgroundImage:[UIImage imageNamed:IMG_BACK_SELECTED] forState:UIControlStateHighlighted];
    [_btnBack addTarget:self action:@selector(backClicked) forControlEvents:UIControlEventTouchUpInside];
    
    _btnShare = [[UIButton alloc] initWithFrame:CGRectMake(_screenSize.width / 2, 0, _screenSize.width / 4, 48)];
    [_btnShare setBackgroundImage:[UIImage imageNamed:IMG_SHARE_NORMAL] forState:UIControlStateNormal];
    [_btnShare setBackgroundImage:[UIImage imageNamed:IMG_SHARE_SELECTED] forState:UIControlStateHighlighted];
    
    _btnCommentHeader = [[UIButton alloc] initWithFrame:CGRectMake(_screenSize.width * 3/4, 0, _screenSize.width/4, 48)];
    [_btnCommentHeader setBackgroundImage:[UIImage imageNamed:IMG_BTN_COMMENT_FOODDETAIL_NORMAL] forState:UIControlStateNormal];
    [_btnCommentHeader setBackgroundImage:[UIImage imageNamed:IMG_BTN_COMMENT_FOODDETAIL_SELECTED] forState:UIControlStateHighlighted];
    
    [_vHeader addSubview:_btnBack];
    [_vHeader addSubview:_btnShare];
    [_vHeader addSubview:_btnCommentHeader];
    
    [self.view addSubview:_vHeader];
    
    [_btnBack release];
    [_btnShare release];
    [_btnCommentHeader release];
    [_vHeader release];
}

- (void) initContent {
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:IMG_VIEW_BACKGROUND]]];
    
    // The menu button doesn't stand in line.
    _vTableContent = [[FoodDetailTableView alloc] initWithFrame:CGRectMake(0, 48, _screenSize.width, _screenSize.height - 48)];
    _vTableContent.tag = IDX_DETAIL_TABLEVIEW;
    _vTableContent._parentView = self;
    _vTableContent._foodBean = _foodBean;
    [self.view addSubview:_vTableContent];
}

// Delegate function
- (void) backClicked {
    [self dismissModalViewControllerAnimated:YES];
}

- (void)pushToSpotDetailScreen:(ZooSpotBean *)spotBean {
    DetailViewController *_detailTableView = [[DetailViewController alloc] initWithSpot:spotBean];

    [self.navigationController pushViewController:_detailTableView animated:YES];
}

@end
